//
//  CommonConfigUtil.m
//  ihotels
//
//  Created by admin on 11-9-19.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <CFNetwork/CFNetwork.h>
#import <SystemConfiguration/SCNetworkReachability.h>
#include <netinet/in.h>


#import "CommonConfigUtil.h"
//#import "CJSONDeserializer.h"
#import "Constants.h"
//#import "ProdListController.h"

@implementation CommonConfigUtil

//原图URL前缀
+(NSString*) getTongChenBigImageUrl{
     return @"http://upload.17u.com/uploadfile/";
}
//图片url前缀
+(NSString*) getTongChenImageBaseUrl{
    return @"http://upload.17u.com/uploadfile/scenerypic_common/";
}
+(NSString*)getGaoDeMapKey{
    return @"a095df56af75c652a62bfd843efdf350";
}
+ (NSString *) getHomeDataFilePath{
 return [NSString stringWithFormat:@"%@/coverPartData.json",[CommonConfigUtil getFileLocalPath]];
}
 //是否显示广告
+ (NSString *) getShowadv{
    return @"0";
}
+ (NSString *) getApp{
 return @"99";
}

+ (NSString *) getCoverId{
    return @"99";
}


+ (NSString *) getCoverName{
    return @"本地游";
}


+ (int) get91AppId{
    return 10831;
    
}

+ (NSString *) get91AppKey{
    return @"4d8b49f0981e4016a2ec2e803bcb1833";
}


//umeng appKey
+ (NSString *) getUmengAppKey{
 return @"5325540756240b57d51c31c1";
}

+ (NSString *)  getChannelId{
return @"appStore";
   // return @"91Store";
}

//当前版本
+ (NSString *) getCurrVersion{
    return @"1.0.3";
}

//版本类型 0:iphone 1:ipad 2:andorid
+(NSString *)getVersionType{
    return @"1";
    
}

//应用推荐类型 0:iphone 1:ipad 2:andorid
+(NSString *)getAppAdvType{
    return @"1";
}



//TTID
+ (NSString *) getTaobaoTTID{
    return [NSString stringWithFormat:@"400000_12448857@TJW_ipad_%@",[CommonConfigUtil getCurrVersion]];

}

//接口地址
+ (NSString *) getInfServiceUrl{
return @"http://api.tujiao.com/webservice";
}



//应用接口地址
+ (NSString *) getCoverUrl{
    return  [NSString stringWithFormat:@"%@/cover/?coverid=%@",[CommonConfigUtil getCommonServiceUrl],[CommonConfigUtil getCoverId]];
    
}

//通用接口地址
+ (NSString *) getCommonServiceUrl{
    return @"http://api.tujiao.com/commonservice";
}


+ (NSString *) getVersionName{
 return @"localtravel";
}



//客户端版本
+ (NSString *) getMobileClientApp{
 
    if([@"91Store" isEqualToString:[CommonConfigUtil getChannelId]]){
      return [NSString stringWithFormat:@"%@_91",[CommonConfigUtil getCurrVersion]];
    
    }
    else{
         return [CommonConfigUtil getCurrVersion];
     
    }

}





//ios device info split with &
+(NSString*) getDeviceInfo{

    //1、得到当前屏幕的尺寸：
    CGRect rect_screen = [[UIScreen mainScreen]bounds];
    CGSize size_screen = rect_screen.size;
    
    //2、获得scale：
    CGFloat scale_screen = [UIScreen mainScreen].scale;
    
    //3\此时屏幕尺寸的宽高与scale的乘积就是相应的分辨率值。
    
    
    return [NSString stringWithFormat:@"&deviceLocalizedModel=%@&deviceModel=%@&deviceSystemVersion=%@&deviceSystemName=%@&deviceScreen=%fx%f",
             [[[UIDevice currentDevice] localizedModel] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding ],
             [[[UIDevice currentDevice] model] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding ],
             [[[UIDevice currentDevice] systemVersion] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
             [[[UIDevice currentDevice] systemName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
             size_screen.width*scale_screen,
             size_screen.height*scale_screen
            ];
    
    
    
}


+(BOOL)checkVersion{
    
    BOOL returnRresult=NO;
    
    if([CommonConfigUtil checkNetworkReachable]){
		
        NSString *url = [[NSString alloc] initWithFormat:@"%@/version/check/?name=%@&type=%@&num=%@&app=%@%@",
                         [CommonConfigUtil getInfServiceUrl],
                         [CommonConfigUtil getVersionName],
                         [CommonConfigUtil getVersionType],
                         // [CommonConfigUtil getCurrVersion],
                         @"0",
                         [CommonConfigUtil getApp],
                         [CommonConfigUtil getDeviceInfo]
                         ];
        
        NSURLRequest *request=[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:
                               NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0];
        
        NSHTTPURLResponse *urlResponse;
        NSData *reData= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:nil];
        
        
		
        NSError *error=nil;
        
        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:reData options:kNilOptions error:&error];
        
       // NSDictionary *dictionary=[[CJSONDeserializer deserializer] deserializeAsDictionary:reData error:&error];
        
        if(!error){
            
            NSArray *versionArray=[dictionary objectForKey:@"versions"];
            if(nil!=versionArray&&[versionArray count]>0){
                
                NSString *versionNumber=[[versionArray objectAtIndex:0] objectForKey:@"versionNumber"];
                NSString *appUrl=[[versionArray objectAtIndex:0] objectForKey:@"appUrl"];
                NSString *appCommentUrl=[[versionArray objectAtIndex:0] objectForKey:@"appCommentUrl"];
                NSString *description=[[versionArray objectAtIndex:0] objectForKey:@"description"];
                
                
                if(nil==versionNumber)versionNumber=@"";
                if(nil==appUrl)appUrl=@"";
                if(nil==appCommentUrl)appCommentUrl=@"";
                if(nil==description)description=@"";
                
                NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
                [myDefaults setObject:versionNumber forKey:@"versionNumber"];
                [myDefaults setObject:appUrl forKey:@"appUrl"];
                [myDefaults setObject:appCommentUrl forKey:@"appCommentUrl"];
                [myDefaults setObject:description forKey:@"description"];
                [myDefaults synchronize];
                
                returnRresult=YES;
                
            }
            else{
                NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
                [myDefaults setObject:@"" forKey:@"versionNumber"];
                [myDefaults setObject:@"" forKey:@"appUrl"];
                [myDefaults setObject:@"" forKey:@"appCommentUrl"];
                [myDefaults setObject:@"" forKey:@"description"];
                [myDefaults synchronize];
                
                returnRresult=YES;
                
            }
            
        }
        
        
        
    }
    
    
    return returnRresult;
    
}


//取得封面配置信息，主要为了取得directLink：1：直接跳转到淘宝页面，0：跳转到详细页面
+(void)getCoverInfo{
    
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    
    NSString *directLink=@"0";
    
    
    if([CommonConfigUtil checkNetworkReachable]){
		
        
        NSURLRequest *request=[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:[CommonConfigUtil getCoverUrl]] cachePolicy:
                               NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0];
        
        NSHTTPURLResponse *urlResponse;
        NSData *reData= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:nil];
        
       
		
        NSError *error=nil;
        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:reData options:kNilOptions error:&error];
        //NSDictionary *dictionary=[[CJSONDeserializer deserializer] deserializeAsDictionary:reData error:&error];
        
        if(!error && nil!=dictionary){
            
            NSString *directLinkValue=[dictionary objectForKey:@"directLink"];
            
            if(nil!=directLinkValue && ([@"1" isEqualToString:directLinkValue]|| [directLinkValue intValue]==1)){
                directLink=@"1";
            }
            else{
                directLink=@"0";
            }
            
            
        }
        
        
        
    }
    
    [myDefaults setObject:directLink forKey:@"directLink"];
    [myDefaults synchronize];
    
    
}



//取得directLink：1：直接跳转到淘宝页面，0：跳转到详细页面
+(BOOL) checkDirectLink{
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    NSString *directLink=[myDefaults objectForKey:@"directLink"];
    if(nil!=directLink && [@"1" isEqualToString:directLink]){
        return YES;
    }
    else{
        return NO;
    }
    
}



+(NSString*) getAppStoreUrl{
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    NSString *appUrl=  [myDefaults objectForKey:@"appUrl"];
    if(nil==appUrl || [@"" isEqualToString:appUrl]){
        [ CommonConfigUtil checkVersion];
        appUrl=  [myDefaults objectForKey:@"appUrl"];
    }
    
    
    return appUrl;
}


+(NSString*) getAppStoreCommentUrl{
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    NSString *appCommentUrl=  [myDefaults objectForKey:@"appCommentUrl"];
    if(nil==appCommentUrl || [@"" isEqualToString:appCommentUrl]){
        [ CommonConfigUtil checkVersion];
        appCommentUrl=  [myDefaults objectForKey:@"appCommentUrl"];
    }
    
    
    return appCommentUrl;
    
}



//图片网络路径
+ (NSString *) getImageNetPath{
    return @"http://static.tujiao.com";
}

//商品图片网络路径
+ (NSString *) getSubjectImageNetPath{   
    return @"http://static.tujiao.com/subject";
}
//商品图片网络路径
+ (NSString *) getSubjectDescImageNetPath{   
    return @"http://static.tujiao.com/subjectDesc";
}

//age图片网络路径
+ (NSString *) getAgeImageNetPath{   
    return @"http://static.tujiao.com/age";
}

//用户图片网络路径
+ (NSString *) getUserImageNetPath{
    return @"http://static.tujiao.com/user";
}

//广告图片网络路径
+ (NSString *) getAdvImageNetPath{
    return @"http://static.tujiao.com/ad";
}


//品牌图片网络路径
+ (NSString *) getBrandImageNetPath{
    return @"http://static.tujiao.com/brandsubject";
}

//专辑图片网络路径
+ (NSString *) getAlbumImageNetPath{
    return @"http://static.tujiao.com/brand";
}

//shop图片网络路径
+ (NSString *) getShopImageNetPath{
    return @"http://static.tujiao.com/shop";
}


//图片本地路径
+ (NSString *) getImageLocalPath{
    return [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches/images"];
}

//file本地路径
+ (NSString *) getFileLocalPath{
    return [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches/files"];
}

//通过表情图片名字得到本地表情图片
+(UIImage *)getLocalFaceWithImageName:(NSString *)faceImageName{
    NSMutableString *faceImageNameMutable=[[NSMutableString alloc]initWithString:[faceImageName substringWithRange:NSMakeRange(1, faceImageName.length-2)]];
    //[faceImageNameMutable replaceOccurrencesOfString:@"face/" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [faceImageNameMutable length])]; 
   // NSLog(@"faceImageName:%@,faceImageNameMutable:%@",faceImageName,faceImageNameMutable);
    UIImage *image= [UIImage imageNamed:faceImageNameMutable];
  
    
    return image;
 
}   




//通过网络表情图片名字得到本地表情图片
+(UIImage *)getLocalFaceWithNetImage:(NSString *)faceImageName{
    
    NSMutableString *faceImageNameMutable=[[NSMutableString alloc]initWithString:[faceImageName substringWithRange:NSMakeRange(1, faceImageName.length-2)]];
     [faceImageNameMutable replaceOccurrencesOfString:@"/" withString:@"_" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [faceImageNameMutable length])];
    
      NSString  *imagePath =[NSString stringWithFormat:@"%@/%@",[self getImageLocalPath],faceImageNameMutable];
    
    
    //文件是否存在
    if([[NSFileManager defaultManager] fileExistsAtPath:imagePath]){
       // NSLog(@"exists:%@",imagePath);
       return [UIImage imageWithContentsOfFile:imagePath];
    }
    else{
       
        NSString *imageUrl=[NSString stringWithFormat:@"%@/%@",[self getImageNetPath],[faceImageName substringWithRange:NSMakeRange(1, faceImageName.length-2)]];
        
       //  NSLog(@"save imageUrl:%@,imagePath:%@",imageUrl,imagePath);
        
        BOOL status=[self writeImage:imageUrl toImagePath:imagePath];
        if(status==YES){	
            return [UIImage imageWithContentsOfFile:imagePath];
        }
        else{
            return nil;
        }

    }
    
       
}


//通过产品ID得到大图本地路径
+ (NSString *) getBigImagePathWithProdId:(NSString *)prodId{
    return [NSString stringWithFormat:@"%@/prod_big_%@.jpg",[self getImageLocalPath],prodId];
}


//通过产品ID得到大图
+ (UIImage *) getBigImageWithProdId:(NSString *)prodId{
    //文件是否存在
    if([[NSFileManager defaultManager] fileExistsAtPath:[self getBigImagePathWithProdId:prodId]]){
        // NSLog(@"exists:%@",imagePath);
        return [UIImage imageWithContentsOfFile:[self getBigImagePathWithProdId:prodId]];
    }
    else{
        return nil;
    } 


}



//通过产品ID得到小图height205本地路径
+ (NSString *) getImagePath205WithProdId:(NSString *)prodId{
  return [NSString stringWithFormat:@"%@/prod_300x205_%@.jpg",[self getImageLocalPath],prodId];
}


//通过产品ID得到小图height205
+ (UIImage *) getImage205WithProdId:(NSString *)prodId{
    //文件是否存在
    if([[NSFileManager defaultManager] fileExistsAtPath:[self getImagePath205WithProdId:prodId]]){
        // NSLog(@"exists:%@",imagePath);
        return [UIImage imageWithContentsOfFile:[self getImagePath205WithProdId:prodId]];
    }
    else{
        return nil;
    } 
}


//通过产品ID得到width 600本地路径
+ (NSString *) getImagePath600WithProdId:(NSString *)prodId{
    return [NSString stringWithFormat:@"%@/prod_600x999_%@.jpg",[self getImageLocalPath],prodId];
}

//通过产品ID得到width 600图
+ (UIImage *) getImage600WithProdId:(NSString *)prodId{
    //文件是否存在
    if([[NSFileManager defaultManager] fileExistsAtPath:[self getImagePath600WithProdId:prodId]]){
        // NSLog(@"exists:%@",imagePath);
        return [UIImage imageWithContentsOfFile:[self getImagePath600WithProdId:prodId]];
    }
    else{
        return nil;
    } 
}



//通过产品ID得到小图本地路径
+ (NSString *) getSmallImagePathWithProdId:(NSString *)prodId{
  return [NSString stringWithFormat:@"%@/prod_200x999_%@.jpg",[self getImageLocalPath],prodId];
}



//文件是否存在
+ (BOOL )  existSmallImageWithProdId:(NSString *)prodId{
    //文件是否存在
    return ([[NSFileManager defaultManager] fileExistsAtPath:[self getSmallImagePathWithProdId:prodId]]);
   
}


//通过产品ID得到小图
+ (UIImage *) getSmallImageWithProdId:(NSString *)prodId{
    //文件是否存在
    if([[NSFileManager defaultManager] fileExistsAtPath:[self getSmallImagePathWithProdId:prodId]]){
        // NSLog(@"exists:%@",imagePath);
        return [UIImage imageWithContentsOfFile:[self getSmallImagePathWithProdId:prodId]];
    }
    else{
        return nil;
    } 
}

//通过图片ID得到width600本地路径
+ (NSString *) getImagePath600WithImageId:(NSString *)imageId{
 return [NSString stringWithFormat:@"%@/prodimage_600x999_%@.jpg",[self getImageLocalPath],imageId];
}

//通过图片ID得到图width600
+ (UIImage *) getImage600WithImageId:(NSString *)imageId{
    //文件是否存在
    if([[NSFileManager defaultManager] fileExistsAtPath:[self getImagePath600WithImageId:imageId]]){
        // NSLog(@"exists:%@",imagePath);
        return [UIImage imageWithContentsOfFile:[self getImagePath600WithImageId:imageId]];
    }
    else{
        return nil;
    } 
}


//通过产品ID得到小图height100本地路径
+ (NSString *) getImagePath100WithProdId:(NSString *)prodId{
    return [NSString stringWithFormat:@"%@/prod_100x100_%@.jpg",[self getImageLocalPath],prodId];

}

//通过产品ID得到小图height100
+ (UIImage *) getImage100WithProdId:(NSString *)prodId{
    //文件是否存在
    if([[NSFileManager defaultManager] fileExistsAtPath:[self getImagePath100WithProdId:prodId]]){
        // NSLog(@"exists:%@",imagePath);
        return [UIImage imageWithContentsOfFile:[self getImagePath100WithProdId:prodId]];
    }
    else{
        return nil;
    } 
}


//通过用户ID得到用户头像50*50本地路径
+ (NSString *) getUserSmallImagePathWithUserId:(NSString *)userId{
 return [NSString stringWithFormat:@"%@/user_50x50_%@.jpg",[self getImageLocalPath],userId];
}

//通过用户ID得到用户头像50*50
+ (UIImage *) getUserSmallImageWithUserId:(NSString *)userId{
    //文件是否存在
    if([[NSFileManager defaultManager] fileExistsAtPath:[self getUserSmallImagePathWithUserId:userId]]){
        // NSLog(@"exists:%@",imagePath);
        return [UIImage imageWithContentsOfFile:[self getUserSmallImagePathWithUserId:userId]];
    }
    else{
        return nil;
    } 


}


//通过用户ID得到用户头像本地路径
+ (NSString *) getUserBigImagePathWithUserId:(NSString *)userId{
 return [NSString stringWithFormat:@"%@/user_125x125_%@.jpg",[self getImageLocalPath],userId];
}

//通过用户ID得到用户头像
+(UIImage *) getUserBigImageWithUserId:(NSString *)userId{

    //文件是否存在
    if([[NSFileManager defaultManager] fileExistsAtPath:[self getUserBigImagePathWithUserId:userId]]){
        // NSLog(@"exists:%@",imagePath);
        return [UIImage imageWithContentsOfFile:[self getUserBigImagePathWithUserId:userId]];
    }
    else{
        return nil;
    } 

}



//通过shop ID得到shop logo本地路径
+ (NSString *) getShopLogoImagePathWithShopId:(NSString *)shopId{
 return [NSString stringWithFormat:@"%@/shoplogo_%@.jpg",[self getImageLocalPath],shopId];
}

//通过shop ID得到shop logo
+(UIImage *) getShopLogoImageWithShopId:(NSString *)shopId{

    //文件是否存在
    if([[NSFileManager defaultManager] fileExistsAtPath:[self getShopLogoImagePathWithShopId:shopId]]){
        // NSLog(@"exists:%@",imagePath);
        return [UIImage imageWithContentsOfFile:[self getShopLogoImagePathWithShopId:shopId]];
    }
    else{
        return nil;
    } 
}



+(NSString *)getSinaWeiboAppKey{
 return @"3839431587";
}


+(NSString *)getSinaWeiboAppSecret{
 return @"3297b2c129d8bbc2cde8bd4599ed02da";
}

+(NSString *)getSinaWeiboWebPath{
 return @"https://api.weibo.com/2";
}

+(NSString *)getQQWebPath{
return @"https://graph.qq.com";
}

//get QQ appid
+(NSString *)getQQAppID{
 return @"101020387";
}


//0:web 1:iphone 2:ipad 3:android
+(NSString *)getUserRegSource{
    return @"2";

}

+ (void)showToast:(ToastPosition)position withTitle:(NSString *)title
{
    iToast *toast = [iToast makeToast:title];
    [toast setToastPosition:position];
    [toast setToastDuration:kToastDurationNormal];
    [toast show];
}


//检查网络
+(BOOL)checkNetworkReachable{  
    // Create zero addy  
    struct sockaddr_in zeroAddress;  
    bzero(&zeroAddress, sizeof(zeroAddress));  
    zeroAddress.sin_len = sizeof(zeroAddress);  
    zeroAddress.sin_family = AF_INET;  
    
    // Recover reachability flags  
    SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);  
    SCNetworkReachabilityFlags flags;  
	
    BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);  
    CFRelease(defaultRouteReachability);  
	
    if (!didRetrieveFlags)  
    {  
        return NO;  
    }  
	
    BOOL isReachable = flags & kSCNetworkFlagsReachable;  
    BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;  
    return (isReachable && !needsConnection) ? YES : NO;  
}  

//写入图片到本地
+(BOOL)writeImage:(NSString*)imageUrl toImagePath:(NSString*) imagePath;
{
	
	if ((imageUrl == nil) || ([@"" isEqualToString:imageUrl]) ||(imagePath == nil) || ([@"" isEqualToString:imagePath]))
		
		return NO;
    
 

    NSData *imageData=[NSData dataWithContentsOfURL:[ NSURL URLWithString:imageUrl]]; 
   
	
	if ((imageData == nil) ||([imageData length] <= 0))
		
		return NO;
	
	@try
	
	{
     //   NSLog(@"begin save:%@",imageUrl);

		[imageData writeToFile:imagePath atomically:YES];
         //  NSLog(@"end save:%@",imageUrl);
        
	    imageData=nil; 
		
		return YES;
		
	}
	
	@catch (NSException *e) 
	
	{
		
        //	NSLog(@"create thumbnail exception.");
		
	}
	
	return NO;
	
}

+(void)writeJsonToLocal:(NSDictionary*)dict localFile:(NSString*)localFile{
    if(dict==nil || dict.count==0)return ;
    
    NSError* error=nil;
    NSData* jsonData= [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    if(!error && jsonData !=nil){
        @try{
            [jsonData writeToFile:localFile atomically:YES];
            jsonData=nil;
        }@catch(NSException* ex) {
            
        }
    }
    
}

+ (void) setImageFromUrl:(NSString*)urlString toImagePath:(NSString*) imagePath{

    [self setImageFromUrl:urlString toImagePath:imagePath completion:NULL];    
}

+ (void) setImageFromUrl:(NSString*)urlString toImagePath:(NSString*) imagePath
              completion:(void (^)(void))completion{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
      //  NSLog(@"Starting: %@", urlString);

        NSURL *url = [NSURL URLWithString:urlString];
        NSData *responseData = [NSData dataWithContentsOfURL:url];
        if ((responseData == nil) ||([responseData length] <= 0))return ;
        @try
        {
            
            [responseData writeToFile:imagePath atomically:YES];
            responseData=nil; 
            
             dispatch_async(dispatch_get_main_queue(), completion);
            
        }
        
        @catch (NSException *e) 
        
        {
    
        }
       //   NSLog(@"Finishing: %@", urlString);
      
	});

}

//get animation
+(CATransition *) getCATransitionWithType:(NSString *)trantype subtype:(NSString *)subtype{

CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration =  0.5f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
    
    //推
    if([@"Push" isEqualToString:trantype]){
        animation.type =kCATransitionPush;
    }//揭开
   else if([@"Reveal" isEqualToString:trantype]){
        animation.type =kCATransitionReveal;
    }//覆盖
   else if([@"MoveIn" isEqualToString:trantype]){
       animation.type =kCATransitionMoveIn;
   }
    //渐变
   else if([@"Fade" isEqualToString:trantype]){
       animation.type =kCATransitionFade;
   }
   else {
     /*  
            mapCurl,mapUncurl,zoomIn,zoomOut
            animation.type = @"cube";//立方体效果
            animation.type = @"suckEffect";//收缩效果，如一块布被抽走 spewEffect
            animation.type = @"oglFlip";//翻转效果
            animation.type = @"rippleEffect";//滴水效果
            animation.type = @"pageCurl";//向上翻一页
            animation.type = @"pageUnCurl";//向下翻一页
            animation.type = @"cameraIrisHollowOpen";//镜头开
            animation.type = @"cameraIrisHollowClose";//镜头关
        */    
     animation.type =trantype;
   }

            
    
    
      
    if([@"Bottom" isEqualToString:subtype]){
        animation.subtype =kCATransitionFromBottom;
    }
    else if([@"Top" isEqualToString:subtype]){
        animation.subtype =kCATransitionFromTop;
    }
    else if([@"Left" isEqualToString:subtype]){
        animation.subtype =kCATransitionFromLeft;
    }
    else if([@"Right" isEqualToString:subtype]){
        animation.subtype =kCATransitionFromRight;
    }
 
    
    return animation;

}


/*
+(void) setAnimationWithType:(NSInteger *)trantype forView:(UIView *)trantView{
    int caseType=trantype;
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.5];
    switch (caseType) {
        case 105:
            [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:trantView cache:YES];
            break;
        case 106:
            [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:trantView cache:YES];
            break;
        case 107:
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:trantView cache:YES];
            break;
        case 108:
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:trantView cache:YES];
            break;
        default:
            break;
    }
    
    
    [UIView setAnimationDelegate:self];
    [UIView commitAnimations];
}*/

+ (BOOL) existFileWithLocalPath:(NSString *)LocalPath{
    return [[NSFileManager defaultManager] fileExistsAtPath:LocalPath];
}
+ (BOOL) existImageWithLocalPath:(NSString *)LocalPath{
    return [[NSFileManager defaultManager] fileExistsAtPath:LocalPath];
}

//通过path得到图
+ (UIImage *) getImageWithLocalPath:(NSString *)LocalPath{
    //文件是否存在
    if([[NSFileManager defaultManager] fileExistsAtPath:LocalPath]){
        // NSLog(@"exists:%@",imagePath);
        return [UIImage imageWithContentsOfFile:LocalPath];
        //return [[UIImage alloc] initWithContentsOfFile:LocalPath];
    }
    else{
        return nil;
    } 

}



//解析以“app:开头的地址”
+ (void)advAppUrlParseWithAppUrl:(NSString *) appurl withUrlparams:(NSString *) urlparams withUINavigationController:(UINavigationController *)navigationController{
    
    NSString *advtype=@"";
    
    NSMutableDictionary *paramsDic=[[NSMutableDictionary alloc] init ];
    
    NSArray *paramsArray=[appurl componentsSeparatedByString:@"&"];
    if(nil!=paramsArray){
        for(int i=0;i<[paramsArray count];i++){
            
            NSArray *keyValueArray=[[paramsArray objectAtIndex:i] componentsSeparatedByString:@"="];
            if(nil!=keyValueArray && [keyValueArray count]>1){
                
                NSString *keyname=[keyValueArray objectAtIndex:0];
                NSString *keyvalue=[keyValueArray objectAtIndex:1];
                if(nil==keyname)keyname=@"";
                if(nil==keyvalue)keyvalue=@"";
                
                if([@"app:advtype" isEqualToString:keyname]){
                    advtype=keyvalue;
                    [paramsDic setObject:keyvalue forKey:@"advtype"];
                }
                else{
                   [paramsDic setObject:[keyvalue stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding ] forKey:keyname];
                }
                
            }
            
            
        }    
    }    
   

    //  NSLog(@"advtype:%@,name:%@,objectId:%@,objectName:%@",advtype,name,objectId,objectName);
   if(nil!=advtype && ![@"" isEqualToString:advtype] && [advtype intValue]!=12){//
        
        NSString *name=[paramsDic objectForKey:@"advname"];
        NSString *objectId=[paramsDic objectForKey:@"objectid"];
        NSString *objectName=[paramsDic objectForKey:@"objectname"];
        if(nil==name)name=@"";
        if(nil==objectId)objectId=@"";
        if(nil==objectName)objectName=@"";
       
       if([advtype intValue]==8 || [advtype intValue]==9){
           
            NSArray *paramsArray=[appurl componentsSeparatedByString:@"objectname="];
           if(nil!=paramsArray &&  [paramsArray count]>1 ){
               objectName= [paramsArray objectAtIndex:1 ];
           }
            if(nil==objectName)objectName=@"";
           // NSLog(@"objectName:%@",objectName);
         
       }
       
       
       
        NSDictionary *params=[NSDictionary dictionaryWithObjectsAndKeys:advtype,@"advtype",name,@"name",objectId,@"objectId",objectName,@"objectName",nil];
        [CommonConfigUtil advSelectWithParams:params withUINavigationController:navigationController]; 
    } 
    
    else if(nil!=advtype && ![@"" isEqualToString:advtype] && [advtype intValue]==12){
    
     
    }

    

}

+ (void)advSelectWithParams:(NSDictionary *) params withUINavigationController:(UINavigationController *)navigationController{

    NSString *advid=[params objectForKey:@"advid" ];
    NSString *advtype=[params objectForKey:@"advtype" ];
    //  NSString *name=[params objectForKey:@"name" ];
    NSString *objectId=[params objectForKey:@"objectId" ];
    NSString *objectName=[params objectForKey:@"objectName" ];
    NSString *urlparams=[params objectForKey:@"urlparams" ];
    
    
    
    if(nil!=advid && ![@"" isEqualToString:advid]){
        
        NSDictionary *statParms =[NSDictionary dictionaryWithObjectsAndKeys:advid,@"objectid",@"ad",@"page",nil];
        [NSThread detachNewThreadSelector:@selector(saveMobileStat:) toTarget:self withObject:statParms];
    }
    
    
    NSLog(@"advtype==%@",advtype);
    //类型 0：商品详细页 1：分类列表 2：标签列表 3：店铺详细 4：品牌详细 5：专辑详细 6：场景详细 7：活动详细 8：appstore 9:url
    
    if([@"0" isEqualToString:advtype] || [advtype intValue]==0 ){
        
 
    }
    else  if([@"1" isEqualToString:advtype] || [advtype intValue]==1 ){
        
    }
    else  if([@"2" isEqualToString:advtype] || [advtype intValue]==2 ){
        
     
        
        
    }
    else  if([@"3" isEqualToString:advtype] || [advtype intValue]==3 ){
        
        
    }
    else  if([@"4" isEqualToString:advtype] || [advtype intValue]==4 ){
        
        
    }
    else  if([@"5" isEqualToString:advtype] || [advtype intValue]==4 ){
        
        
    }
    else  if([@"8" isEqualToString:advtype] || [advtype intValue]==8 ){
        
        
        NSString *appName=@"";
        if(nil!=urlparams && ![@"" isEqualToString:urlparams] ){
            NSArray *paramsArray=[urlparams componentsSeparatedByString:@"appname="];
            if(nil!=paramsArray &&  [paramsArray count]>1 ){
                appName= [paramsArray objectAtIndex:1 ];
            }
            
        }
        
        if(nil==appName)appName=@"";
        
        if(![@"" isEqualToString:appName] && [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:appName]]){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appName]];
        }
        else{
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:objectName]];
        }
        
    }
    else  if([@"9" isEqualToString:advtype] || [advtype intValue]==9 ){
        
        //start with app:
        if ([objectName hasPrefix:@"app:"]){
            [self advAppUrlParseWithAppUrl:objectName withUrlparams:urlparams withUINavigationController:navigationController];
        }
        else if(nil!=objectId && ([@"1" isEqualToString:objectId] || [objectId intValue]==1)  ) {
            
      
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:objectName]];
            
        }
        else {
            
        }
    }
    


    
}

+ (void)advSelectWithParams:(NSDictionary *) params withNavController:(UIViewController *)naviViewController{
    [self advSelectWithParams:params withUINavigationController:naviViewController.navigationController];
      
}




//手机操作统计
+ (void) saveMobileStat:(NSDictionary *)params{
    
    
    if(![self checkNetworkReachable]){
		return ;
	}
    
    if(nil==[params objectForKey:@"objectid"] || [@"" isEqualToString:[params objectForKey:@"objectId"]]){
        return ;
    }


              
    NSString *openUDID=[[[UIDevice currentDevice] identifierForVendor] UUIDString];
    /*
    NSString *openUDID=[OpenUDID value];
    
    if(nil==openUDID){
        openUDID=@"";
    }*/
    
    
    NSMutableString *url = [[NSMutableString alloc] initWithFormat:@"%@/mobile/stat/?source=%@&uuid=%@",[CommonConfigUtil getInfServiceUrl],[CommonConfigUtil getVersionType],openUDID]; 
    
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    if(nil!=[myDefaults objectForKey:@"userId"]&&![@"" isEqualToString:[myDefaults objectForKey:@"userId"]]){
        [url appendFormat:@"&userid=%@", [myDefaults objectForKey:@"userId"]];
    }
    
    if(nil!=[myDefaults objectForKey:@"userNickname"]&&![@"" isEqualToString:[myDefaults objectForKey:@"userNickname"]]){
        [url appendFormat:@"&username=%@", [[myDefaults objectForKey:@"userNickname"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    }
    
    if(nil!=[myDefaults objectForKey:@"deviceToken"]&&![@"" isEqualToString:[myDefaults objectForKey:@"deviceToken"]]){
        [url appendFormat:@"&token=%@",[[myDefaults objectForKey:@"deviceToken"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    }
  
    
    if(nil!=[params objectForKey:@"objectid"]&&![@"" isEqualToString:[params objectForKey:@"objectId"]]){
        [url appendFormat:@"&objectid=%@",[params objectForKey:@"objectid"]];
    }
    if(nil!=[params objectForKey:@"page"]&&![@"" isEqualToString:[params objectForKey:@"page"]]){
        [url appendFormat:@"&page=%@",[params objectForKey:@"page"]];
    }
    
    
   // NSLog(@"url:%@",url);
    
    //  NSData *reData=[NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
    // [url release];
    
    NSURLRequest *request=[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy: 
                           NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0];
    
    NSHTTPURLResponse *urlResponse;
    NSData *reData= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:nil];
    
 
    
    
    reData=nil;
    
    
    
  
    

}
 
+(NSInteger)getRoladDataTimeSecond{
    return 3600*24*3;//三天
}


//sina weibo,qq share
+ (void) weiboShare:(NSDictionary *)params{
    
    
    if(![self checkNetworkReachable]){
		return ;
	}
    
    
    
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    NSString *userId=[myDefaults objectForKey:@"userId"];
    
    NSString *sharetype=[params objectForKey:@"sharetype"];//分享类型 1:商品分享 7：店铺分享 8：应用分享
    NSString *objectid=[params objectForKey:@"objectid"];
    
    
    if(nil==userId || [@"" isEqualToString:userId] || nil==sharetype || [@"" isEqualToString:sharetype]){
        return;
    }
    
    
      
    NSMutableString *url = [[NSMutableString alloc] initWithFormat:@"%@/weibo/share/?type=%@&name=%@&app=%@&userid=%@&sharetype=%@",[CommonConfigUtil getInfServiceUrl],[CommonConfigUtil getVersionType],[CommonConfigUtil getVersionName], [CommonConfigUtil getApp],userId,sharetype]; 
    
    
    if(nil!=objectid&&![@"" isEqualToString:objectid]){
        [url appendFormat:@"&objectid=%@",objectid];
    }
    
    
    //NSLog(@"url:%@",url);
    
    //  NSData *reData=[NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
    // [url release];
    
    NSURLRequest *request=[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy: 
                           NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0];
    
    NSHTTPURLResponse *urlResponse;
    NSData *reData= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:nil];
    
  
    
    
    reData=nil;
    
    
    
   
    
    
}


@end
